<?php
session_start();
require 'data/data.php';

$isSignin = isset($_SESSION['user']) && !empty($_SESSION['user']);
$user = $isSignin ? $_SESSION['user'] : null;
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <link rel="stylesheet" href="public/css/shopcar.css"/>
</head>
<body>
<div class="header">
    <img src="public/img/vancl-logo.png" alt="vancl"/>
    <!--未登录-->
<?php if(!$isSignin): ?>
    <p class="userInfo">
        您好,欢迎光临凡客诚品！
        <a href="">登录</a>
        <span class="spacer">|</span>
        <a href="">注册</a>
    </p>
    <!--未登录-->
<?php else: ?>
    <!--已登录-->
    <p class="userInfo">
        您好,<span class="username"><?php echo $user['user_name']?></span>！
        <a href="action/logout_action.php">退出登录</a>
        <span class="spacer">|</span>
        <a href="">更换用户</a>
    </p>
<?php endif; ?>   
    <!--已登录-->
    <a href="">帮助中心</a>
</div>
<div class="body">
    <p>我的购物车</p>
    <span class="warning"><span class="c_red">温馨提示：</span>1.选购清单中的商品无法保留库存，请您及时结算。2.商品的价格和库存将以订单提交时为准。3.促销活动满减优惠将均摊至商品小计中。</span>
</div>


<!--没有商品-->
<?php if(empty($cart) || count($cart) == 0): ?>
<div class="empty">
    您的购物车中没有商品，请您先 <a href="index.php">选购商品»</a>
</div>
<?php else: ?>
<div class="contents">
    <ul>
        <li><input type="checkbox" name="selectAll" id="selectAll" /><label for="selectAll">全选</label></li>
        <li class="ml_200">商品信息</li>
        <li class="ml_200">单价</li>
        <li class="ml_80">数量</li>
        <li class="ml_80">小计</li>
        <li class="ml_80">操作</li>
    </ul>
  <?php foreach($cart as $g): ?>
    <div class="content">
        <input type="checkbox" class="sel"/>
        <img src="<?php echo $g['image'] ?>" alt=""/>
        <span class="gname"><?php echo $g['name'] ?></span>
        <span class="price">¥<?php echo $g['price'] ?></span>
        <span class="num">
          <a href="action/cart_num_action.php?op=1&id=<?php echo $g['id']?>">-</a>
          <input type="text" class="number" value="<?php echo $g['num']  ?>" />
          <a href="action/cart_num_action.php?op=2&id=<?php echo $g['id']?>">+</a>
        </span>
        <span class="count">¥<?php echo $g['num'] * $g['price'] ?></span>
        <a href="action/delete_cart_action.php?id=<?php echo $g['id'] ?>" class="del">删除</a>
    </div>
   <?php endforeach; ?>
</div>
<div class="pay">
    <p><a class="delSel">删除选中</a><span class="totalNum">数量总计:0件</span></p>
    <p>产品金额总计(不含运费): <span class="totalMoney">¥0.00</span><a href="">继续购物</a><a href="">去结算</a></p>
</div>
<!--有商品-->
<?php endif; ?>
<div class="tail">
    <p>Copyright 2007 - 2017 vancl.com All Rights Reserved 京ICP证100557号 京公网安备11010102000579号 出版物经营许可证新出发京批字第直110138号</p>
</div>
</body>
</html>
